package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.HsgtStats;
import com.stylefeng.guns.modular.system.service.IHsgtStatsService;
import com.stylefeng.guns.modular.system.warpper.HsgtStatsWarpper;

/**
 * 沪深股通资金统计控制器
 *
 * @author fengshuonan
 * @Date 2018-07-06 17:34:04
 */
@Controller
@RequestMapping("/hsgtStats")
public class HsgtStatsController extends BaseController {

    private String PREFIX = "/system/hsgtStats/";

    @Autowired
    private IHsgtStatsService hsgtStatsService;

    /**
     * 跳转到沪深股通资金统计首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "hsgtStats.html";
    }

    /**
     * 跳转到添加沪深股通资金统计
     */
    @RequestMapping("/hsgtStats_add")
    public String hsgtStatsAdd() {
        return PREFIX + "hsgtStats_add.html";
    }

    /**
     * 跳转到修改沪深股通资金统计
     */
    @RequestMapping("/hsgtStats_update/{hsgtStatsId}")
    public String hsgtStatsUpdate(@PathVariable Integer hsgtStatsId, Model model) {
        HsgtStats hsgtStats = hsgtStatsService.selectById(hsgtStatsId);
        model.addAttribute("item",hsgtStats);
        LogObjectHolder.me().set(hsgtStats);
        return PREFIX + "hsgtStats_edit.html";
    }

    /**
     * 获取沪深股通资金统计列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) Integer salesCode) {
    	Page<HsgtStats> page = new PageFactory<HsgtStats>().defaultPage();
    	List<Map<String, Object>> gdhs = hsgtStatsService.selectMapsByDm(page,salesCode);
    	page.setRecords((List<HsgtStats>) new HsgtStatsWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增沪深股通资金统计
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(HsgtStats hsgtStats) {
        hsgtStatsService.insert(hsgtStats);
        return SUCCESS_TIP;
    }

    /**
     * 删除沪深股通资金统计
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer hsgtStatsId) {
        hsgtStatsService.deleteById(hsgtStatsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改沪深股通资金统计
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(HsgtStats hsgtStats) {
        hsgtStatsService.updateById(hsgtStats);
        return SUCCESS_TIP;
    }

    /**
     * 沪深股通资金统计详情
     */
    @RequestMapping(value = "/detail/{hsgtStatsId}")
    @ResponseBody
    public Object detail(@PathVariable("hsgtStatsId") Integer hsgtStatsId) {
        return hsgtStatsService.selectById(hsgtStatsId);
    }
}
